#ifndef __RCO_CMDPASER_HANDLER_H__
#define __RCO_CMDPASER_HANDLER_H__

#include <QMap>
#include <QVector>
#include "../rcodef/rcointerface.h"

class QString;
class QStringList;
class QByteArray;
namespace rco
{
typedef QMap<QString, rco_cid> RcoCmds;
typedef void (*fnParamParsedCallback)(const QVector<QString*>& params, RcoCommand* pRcoCmd);

inline void ParamParsedDefaultCallback(const QVector<QString*>& params, RcoCommand* pRcoCmd)
{
	Q_ASSERT(params.size() >= 2);

	pRcoCmd->pStrParam1 = params[0];
	pRcoCmd->pStrParam2 = params[1];
}

class RcoCmdParser
{
public:
	RcoCmdParser()
	{
		m_fnCb = nullptr;
		m_ppCmdInfos = nullptr;
	}

	bool Init(fnParamParsedCallback fnCb = ParamParsedDefaultCallback);

	CmdParserResult OnCommandParsing(const QString& strCmd, RcoCommandHead* pRcoCmd, int* pPosParsed);
	CmdParserResult OnSwitchParsing(const QString& strSwitch, const RcoCmdInfoBase* pCmdInfo, RcoCommandHead* pRcoCmd);

	static int OnParamParsing(const QString& strCmd, int iBeg, int n, QString params[]);
	static int OnParamParsing(const QByteArray& bytes, int iBeg, int n, QString params[]);

protected:
	RcoCmds					m_cmdStrMap;
	fnParamParsedCallback   m_fnCb;
	const RcoCmdInfoBase**	m_ppCmdInfos;
};

};

#endif // __RCO_CMDPASER_HANDLER_H__